package grpc

import (
	"context"

	"gitee.com/xgotool/sqlite-logs-more/model"
	"gitee.com/xgotool/sqlite-logs-more/protoc"
	"gitee.com/xgotool/sqlite-logs-more/service/logs"
	"github.com/golang/protobuf/ptypes/empty"
	"google.golang.org/protobuf/types/known/emptypb"
)

// 记录三方请求日志记录
func (c *GrpcRemote) QuestLog(cnt context.Context, app *protoc.Quest) (*empty.Empty, error) {
	der, err := getDid(cnt)
	if err != nil {
		return nil, notFond(err)
	}
	if c.Dervice == nil {
		c.Dervice = der
	}
	pipe_log := model.QuestLog{
		Id:       app.Id,
		Did:      der.Id,
		Args:     app.Args,
		Uri:      app.Uri,
		Param:    app.Param,
		HttpCode: app.HttpCode,
		Body:     app.Body,
		Error:    app.Error,
		Header:   app.Header,
		QuestSec: app.QuestEsc,
		ClientIp: app.ClientIp,
		Uid:      app.Uid,
		Uuid:     app.Uuid,
		Ruid:     app.Ruid,
	}
	err = logs.QuestLogCreate(&pipe_log)
	if err != nil {
		return nil, sysErr(err)
	}
	return &emptypb.Empty{}, nil
}
